﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cn.Util;
using System.Linq.Expressions;

namespace yq.IBase.Basis
{
    /// <summary>
    /// 视图相关
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ViewBase<T> where T : ModelBase<T>, new()
    {
        /// <summary>
        /// 传入sql语句分页查询 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="page"></param>
        /// <param name="cn"></param>
        /// <returns></returns>
        public virtual PageList<T> GetPageList(string sql,string orderby, PageModel page, DbHelper cn)
        {
            return new SelectBase<T>().GetPageList(sql, orderby, page, cn);
        }

        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        public virtual SelectBase<T> Where(Expression<Func<T, bool>> func)
        {
            SelectBase<T> select = new SelectBase<T>();
            select.Where(func);

            return select;
        }

        /// <summary>
        /// 查询条件 空条件
        /// </summary>
        /// <returns></returns>
        public virtual SelectBase<T> Where()
        {
            return new SelectBase<T>();
        }

        /// <summary>
        /// 查询全部数据
        /// </summary>
        /// <param name="cn"></param>
        /// <returns></returns>
        public virtual IList<T> GetAllList(DbHelper cn)
        {
            return new SelectBase<T>().ToList(cn);
        }
    }
}
